package thread.baozi;

public class Consumer extends Thread {
    private BaoZi baoZi;

    public Consumer(BaoZi baoZi) {
        this.baoZi = baoZi;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (baoZi) {
                if (!baoZi.isFlag()) {
                    try {
                        baoZi.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("顾客正在吃+" + baoZi.getPi() + baoZi.getXian() + "的包子");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("顾客已经把包子吃完了");
                baoZi.setFlag(false);
                baoZi.notify();
            }
        }
    }
}
